<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: Ringo Chan <334258471@qq.com> <http://www.jxlnxx.com/>
// +----------------------------------------------------------------------

namespace Api\Controller;
use User\Api\UserApi;
use Discernbank\DiscernBank;
use Api\Model\MemberGiftModel;
use Api\Controller\HxController;
use Api\Model\OrderModel;
use Com\Easemob;
/**
 * API用户控制器
 * 主要获取用户数据
 */
class UserController extends ApiController {

    /**
     * 用户登录
     * 
     * @author Ringo Chan<334258471@qq.com>
     */
	public function login(){
//	    $this->api_login() && response(-96);

	    params_exist(array('user', 'pwd', 'driver'));
	    
	    $username = I('post.user');
	    $password = I('post.pwd');
	    $driver = I('post.driver');

		$user = new UserApi;

		$uid = $user->login($username, $password);

		if(0 < $uid){
			$Member = D('Member');
			$userinfo = M('member')->where('uid='.$uid)->getField('nickname');
			$is_disable = M('user_disable')->where('username='.$userinfo)->find();
			if ($is_disable) {
				response(-2, '', '该用户已被禁用');
			}
			if($Member->login($uid)){
			    M('member_token')->where(array('uid'=>$uid, 'deadline' => array('egt', NOW_TIME)))->setField('is_online',0);
				//发货后12天后自动修改为完成状态
				//$order = A('order')->autoTake($uid);
			    $token = addToken($uid, $driver);
				response(1, array('token'=>$token));
			} else {
				response(-1, '', $Member->getError());
			}

		} else {
			switch($uid) {
				case -1: $code = -7; $error = '用户不存在或被禁用！'; break;
				case -2: $code = -1; $error = '密码错误！'; break;
				default: $code = -9; $error = '未知错误！'; break;
			}			
			response($code, '', $error);
		}
	}
	
	/**
     * 用户注册
     * @author Ringo Chan<334258471@qq.com>
     */
	public function register(){
	    //params_exist(array('user', 'pwd', 'repwd', 'verify'));
	    params_exist(array('user', 'pwd', 'repwd'));

	    $username = I('post.user');
	    $password = I('post.pwd');
	    $repassword = I('post.repwd');
	    $verify = I('post.verify');
	    $referrer = I('post.referrer', 0);
	    
	    empty($verify) && response('-1', '', '验证码不能为空');
	    empty($username) && response('-1', '', '手机号码不能为空');
	    !preg_match('/1[3458]{1}\d{9}$/', $username) && response(-1, '', '请正确输入您的手机号码');
	    !preg_match('/^[a-zA-Z]\w{5,30}$/', $password) && response('-2', '', '密码首字符必须为英文字母，长度必须在6-30个字符之间');
	    $password != $repassword && response(-2, '', '两次密码输入不一致');
	    $Message_verify = M('Message_verify');
	    $map = array('type'=>'register', 'username'=>$username, 'code'=>$verify, 'deadline'=>array('egt', NOW_TIME), 'status' => 1);
	    $info = $Message_verify->where($map)->find();
	    $info || response('-4', '', '无效验证码或验证码已过期');
	    if (!empty($referrer)) {
	        $referrer = M('ucenter_member')->where(array('username'=>$referrer))->getField('id');
	        $referrer || response('-2', '', '推荐码错误');
	    }
        $User = new UserApi;
		$uid = $User->register($username, $password);
		//环信创建用户
		$hx = new HxController();
		$hxid = $hx->createUser($username, '123456');
		$res_data['nickname'] = $username;
        $res_data['username'] = $username;
        $res_data['password'] = $password;

        if(0 < $uid && !isset($hxid['error'])){
		    $data = D('member')->create(array('nickname' => $username, 'referrer'=>$referrer, 'status' => 1,'zd_id'=>'ZDH'.$uid,'mobile' => $username));
		    $member = D('member')->add($data);
		    if (!$member) {
		    	M('ucenter_member')->where('username='.$username)->delete();
			}
		    //产生分组
			$userGroup = M('user_group')->add(array('uid'=>$uid));
		    if (!$userGroup) {
                M('user_group')->add(array('uid'=>$uid));
			}
            $hx=new Easemob();
            $options = array(
                "groupname" => '自带军团', //群组名称，此属性为必须的
                "desc" => '自带军团', //群组描述，此属性为必须的
                "public" => true, //是否是公开群，此属性为必须的true or false
                "maxusers" => 300, //群组成员最大数（包括群主），值为数值类型，默认值200，最大值2000，此属性为可选的
                "approval" => true, //加入公开群是否需要批准，默认值是false（加入公开群不需要群主批准），此属性为必选的，私有群必须为true
                "owner" => $username, //群组的管理员，此属性为必须的
            );
            $result1 = $hx->createGroup($options);
			//产生再带团号
			$data = array(
				'id'=>$result1['data']['groupid'],
				'name'=>'自带军团',
				'uid'=>$uid,
				'update_time'=>NOW_TIME,
				'number'=>'ZDT'.substr($username, 5),
				'self'=>1
			);
			$res1 = M('group')->add($data);
			//为群添加自己
			$data1 = array(
                'gid'=>$result1['data']['groupid'],
				'username'=>$username,
				'is_manager'=>1
			);
			$res2 = M('group_member')->add($data1);
		    $result = $Message_verify->where($map)->setField('status', 0);
		    if ($res2) {
                response(1,$res_data);
			} else {
                response(-9);
			}
		} else {
			response($uid, '', $this->showRegError($uid));
		}
	}

	
	/**
	 * 找回密码
	 * @author Ringo Chan<334258471@qq.com>
	 */
	public function forgotten(){
	     
	     params_exist(array('user', 'verify'));
	     
	     $username = I('post.user');
	     $verify = I('post.verify');
	      
	     empty($verify) && response('-1', '', '验证码不能为空');
	     empty($username) && response('-1', '', '手机号码不能为空');
	      
	     $Message_verify = M('Message_verify');
	      
	     $map = array(
	         'type'=>'forgotten',
	         'username'=>$username,
	         'code'=>$verify,
	         'deadline'=>array('egt', NOW_TIME),
	         'status' => 1
	     );
	      
	     $info = $Message_verify->where($map)->find();
	     
	     !$info && response('-4', '', '无效验证码或验证码已过期');
	     
	     $verify = getRandCode(16, 'string');
	     
	     $data = array(
	         'username' => $username,
	         'verify' => $verify,
	         'create_time' => NOW_TIME,
	         'deadline' => NOW_TIME + 1800,
	         'status' => 1
	     );
	     
	     M('Member_forgotten')->add($data) && $Message_verify->where($map)->setField('status', 0);
	     
	     response(1, array('verify'=>$verify));
	}
	
	/**
	 * 找回密码->设置密码
	 * 
	 * @author Ringo Chan<334258471@qq.com>
	 */
	public function resetPassword() {
//	    $this->api_login() && response(-96);
	    
	    params_exist(array('user', 'verify', 'pwd', 'repwd'));
	    
	    $username = I('post.user');
	    $verify = I('post.verify');
	    $password = I('post.pwd');
	    $repassword = I('post.repwd');
	    
	    empty($verify) && response('-1', '', '验证码不能为空');
	    empty($username) && response('-1', '', '手机号码不能为空');
	    !preg_match('/^[a-zA-Z]\w{6,30}$/', $password) && response('-2', '', '密码首字符必须为英文字母，长度必须在6-30个字符之间');
	    $password != $repassword && response(-2, '', '两次密码输入不一致');
	    
	    $map = array(
	        'username'=>$username, 
	        'code'=>$verify, 
	        'deadline'=>array('egt', NOW_TIME),
	        'status'=>1
	    );
	    
	    $info = M('Message_verify')->where($map)->find();
	    // echo M('Message_verify')->getLastsql();
	    // dump($info);
	    !$info && response(-4, '', '验证失效');
	    
	    $user = new UserApi();
	    
	    $res = $user->updatePassword($username, $password);
	    if ($res['status'] ){
	        M('Message_verify')->where($map)->setField('status', 0);
	        response(1);
	    } else {
	        response(-9, '', $res['info']);
	    }
	}
	
	/**
	 * 获取用户昵称
	 * 
	 * @param string token 登录标识
	 * @author Ringo Chan<334258471@qq.com>
	 */
	public function getNickname(){
	    !api_login() && response(-94);
	    !passed_login() && response(-95);
	    !only_login() && response(-96);

	    $this->getMemberInfo('nickname');
	}
	
	/**
	 * 编辑用户昵称
	 * 
	 * @param string token 登录标识
	 * @param string nickname
	 * @author Ringo Chan<334258471@qq.com>
	 */
	public function editNickname(){
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);
	    
	    params_exist(array('nickname'));
	    
	    $nickname = I('post.nickname');
	    
	    empty($nickname) && response('-1', '', '昵称不能为空');
	    !preg_match('/^[\x{4e00}-\x{9fa5}A-Za-z][\x{4e00}-\x{9fa5}A-Za-z0-9_]{3,30}+$/u', $nickname) && response(-1, '', '昵称格式错误，长度必须在4~30个字符或首字母不能为数字下划线');
        $Member = D('Member');
	    $username = $Member->where(array('uid'=>API_UID))->getField('nickname');
	    $hx = new hxController();
        $hxresult = $hx->editNickname($username, $nickname);
	    $result = $Member->where(array('uid'=>API_UID))->setField('nickname', $nickname);
	    if ($result && !isset($hxresult['error'])) {
            response(1);
		} else {
            response(-9, '', '未知错误');
		}
	}
	
	/**
	 * 修改用户密码
	 * 
	 * @param string token 登录标识
	 * @param string oldpwd 旧密码
	 * @param string newpwd 新密码
	 * @param string repwd 确认密码
	 * @author Ringo Chan<334258471@qq.com>
	 */
	public function editPassword(){
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);
	    
	    params_exist(array('oldpwd', 'newpwd', 'repwd'));
	    
	    $oldpwd = I('post.oldpwd');
	    $newpwd = I('post.newpwd');
	    $repwd = I('post.repwd');
	    
	    empty($oldpwd) && response(-1, '', '旧密码不能为空');
	    empty($newpwd) && response(-1, '', '新密码不能为空');
	    !preg_match('/^[a-zA-Z]\w{6,30}$/', $newpwd) && response('-2', '', '密码首字符必须为英文字母，长度必须在6-30个字符之间');
	    $newpwd != $repwd && response(-1, '', '两次密码输入不一致');
	    
	    $user = new UserApi();
	    !$user->verifyUser(API_UID, $oldpwd) && response(-2, '', '旧密码不匹配，请重新输入');
	    
	    $Ucenter_member = M('Ucenter_member');
	    $info = $Ucenter_member->find(API_UID);
	     
	    $user = new UserApi();
	     
	    $res = $user->updatePassword($info['username'], $newpwd);
	    if ($res['status']){
	        response(1);
	    } else {
	        response(-9, '', $res['info']);
	    }
	}
	
	/**
	 * 获取用户性别
	 * 
	 * @param string token 登录标识
	 * @author Ringo Chan<334258471@qq.com>
	 */
	public function getSex(){
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);

	    $this->getMemberInfo('sex');
	}
	
	/**
	 * 修改用户性别
	 * 
	 * @param string token 登录标识
	 * @param integer sex
	 * @author Ringo Chan<334258471@qq.com>
	 */
	public function editSex(){
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);
	     
	    params_exist(array('sex'));
	    
	    $sex = I('post.sex');
	    
	    !in_array($sex, array(0, 1, 2)) && response(-1, '', '错误性别');
	    
	    $Member = D('Member');
	    
	    $Member->where(array('uid'=>API_UID))->setField('sex', $sex) ? response(1) : response(-9, '', '未知错误');
	}
	
	/**
	 * 获取用户手机号码
	 *
	 * @param string token 登录标识
	 * @author Ringo Chan<334258471@qq.com>
	 */
	public function getMobile(){
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);
	
	    $Ucenter_member = M('Ucenter_member');
	    $info = $Ucenter_member->find(API_UID);
	    
	    $info ? response(1, array('mobile'=>$info['mobile'])) : response(-9);
	}
	
	/**
	 * 修改用户手机号码
	 *
	 * @param string token 登录标识
	 * @param string mobile 更改的手机号
	 * @param string verify 验证码
	 * @author Ringo Chan<334258471@qq.com>
	 */
	public function editMobile(){
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);
	
	    params_exist(array('mobile', 'verify'));
	    
	    $verify = I('post.verify');
	    $mobile = I('post.mobile');
	    
	    empty($verify) && response('-1', '', '验证码不能为空');
	     
	    $Message_verify = M('Message_verify');
	    
	    $map = array(
	        'type'=>'modifymobile',
	        'username'=>$mobile,
	        'code'=>$verify,
	        'deadline'=>array('egt', NOW_TIME),
	        'status' => 1
	    );
	     
	    $info = $Message_verify->where($map)->find();
	    
	    !$info && response('-4', '', '无效验证码或验证码已过期');
	     
	    !preg_match('/1[3458]{1}\d{9}$/', $mobile) && response(-1, '', '请正确输入您的手机号码');
	    get_table_field($mobile, 'username', 'id', 'ucenter_member') && response(-2, '', '手机号码已注册');
	    
	    $Message_verify->where($map)->setField('status', 0);
	     
	    $Ucenter_member = M('Ucenter_member');
	     
	    $Ucenter_member->where(array('id'=>API_UID))->save(array('mobile'=>$mobile, 'username'=>$mobile)) ? response(1) : response(-9);
	}
	
	/**
	 * 获取收货地址列表
	 * 
	 * @param string token 登录标识
	 * @author Ringo Chan<334258471@qq.com>
	 */
	public function getReceiveAddrs(){
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);
	    
	    $list = array();
	    
	    $Member_receive = M('Member_receive');
	    
	    $results = $Member_receive->where(array('uid'=>API_UID))->order('update_time DESC')->select();
	    
	    foreach ($results as $result) {
	        $list[] = array(
	            'id' => $result['id'],
	            'realname' => $result['realname'],
	            'mobile' => $result['mobile'],
	            'address' => $result['address'],
	            'province_id' => $result['province_id'],
	            'province' => get_table_field($result['province_id'], 'province_id', 'province', 'hat_province'),
	            'city_id' => $result['city_id'],
	            'city' => get_table_field($result['city_id'], 'city_id', 'city', 'hat_city'),
	            'area_id' => $result['area_id'],
	            'area' => get_table_field($result['area_id'], 'area_id', 'area', 'hat_area'),
	            'is_default' => $result['is_default']
	        );
	    }
	    
	    response(1, $list);
	}
	
	/**
	 * 获取用户收货地址详情
	 * 
	 * @param string token 登录标识
	 * @param integer id 收货地址编号
	 * @author Ringo Chan<334258471@qq.com>
	 */
	public function getReceiveAddr(){
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);
	    
	    params_exist(array('id'));
	    
	    $id = I('post.id');
	    
	    $Member_receive = M('Member_receive');
	    
	    $info = $Member_receive->where(array('id'=>$id, 'uid'=>API_UID))->field(array('mobile', 'realname', 'province_id', 'city_id', 'area_id', 'is_default', 'address'))->find();
	    $info['province'] = get_table_field($info['province_id'], 'province_id', 'province', 'hat_province');
	    $info['city'] = get_table_field($info['city_id'], 'province_id', 'city', 'hat_city');
	    $info['area'] = get_table_field($info['area_id'], 'province_id', 'area', 'hat_area');
	    
	    $info ? response(1, $info) : response(-1, '', '没有找到匹配数据');
	}
	
	/**
	 * 获取删除地址
	 *
	 * @param string token 登录标识
	 * @param integer id 收货地址编号
	 */
	public function delReceiveAddr(){
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);
	     
	    params_exist(array('id'));
	     
	    $id = I('post.id');
	     
	    $Member_receive = M('Member_receive');
	     
	    $map=array('id'=>$id, 'uid'=>API_UID);
	    $info = $Member_receive->where($map)->find();
	     
	    empty($info) && response(-1, '', '地址不存在');
	    
	    $Member_receive->where($map)->delete() ? response(1) : response(-9);
	}
	
	/**
	 * 添加用户收货地址
	 * 
	 * @param string token 登录标识
	 * @param string mobile 联系手机号码
	 * @param string realname 姓名
	 * @param integer province_id 省份ID
	 * @param integer city_id 城市ID
	 * @param integer area_id 县\区ID
	 * @param string address 详细地址
	 * @author Ringo Chan<334258471@qq.com>
	 */
	public function addReceiveAddr(){

        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);
	    
	    params_exist(array('mobile', 'realname', 'province_id', 'city_id', 'area_id', 'address'));
	    
	    $mobile = I('post.mobile');
	    $realname = I('post.realname');
	    $province_id = I('post.province_id', 0);
	    $city_id = I('post.city_id', 0);
	    $area_id = I('post.area_id', 0);
	    $address = I('post.address');
	    $is_default = I('post.is_default',0);
	    
	    !preg_match('/1[3458]{1}\d{9}$/', $mobile) && response(-1, '', '请正确输入您的手机号码');
	    !preg_match('/^0|1$/', $is_default) && response(-1, '', '是否为默认地址只能为0或1');
	    !preg_match('/^[\x{4e00}-\x{9fa5}]{1,10}+$/u', $realname) && response(-1, '', '请输入联系人，必须为中文');
	    !get_table_field($province_id, 'province_id', 'province_id', 'Hat_province') && response(-1, '', '选择的省份没有匹配对象');
	    !get_table_field($city_id, 'city_id', 'city_id', 'Hat_city') && response(-1, '', '选择的城市没有匹配对象');
	    !get_table_field($area_id, 'area_id', 'area_id', 'Hat_area') && response(-1, '', '选择的区县没有匹配对象');
	    !preg_match('/^[\x{4e00}-\x{9fa5}][\x{4e00}-\x{9fa5}A-Za-z0-9_-]{5,50}+$/u', $address) && response(-1, '', '详细地址长度必须在5~50个字符');
	    	        
	    
	    $data = array(
	        'uid' => API_UID,
	        'realname' => $realname,
	        'mobile' => $mobile,
	        'province_id' => $province_id,
	        'city_id' => $city_id,
	        'area_id' => $area_id,
	        'address' => $address,
	        'is_default' => $is_default,
	        'create_time' => NOW_TIME,
	        'update_time' => NOW_TIME
	    );
	    
	    $Member_receive = M('Member_receive');
	    if($is_default){
	        $Member_receive->where(array('uid'=>API_UID))->setfield('is_default',0);
	    }
	    
	    $Member_receive->add($data) ? response(1) : response(-9);
	}
	
	/**
	 * 编辑用户收货地址
	 * @param integer id 收货地址编号
	 * @param string token 登录标识
	 * @param string mobile 联系手机号码
	 * @param string realname 姓名
	 * @param integer province_id 省份ID
	 * @param integer city_id 城市ID
	 * @param integer area_id 县\区ID
	 * @param string address 详细地址
	 * @author Ringo Chan<334258471@qq.com>
	 */
	public function editReceiveAddr(){
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);
	     
	    params_exist(array('id', 'mobile', 'realname', 'province_id', 'city_id', 'area_id', 'address'));
	    
	    $id = I('post.id');
	    $mobile = I('post.mobile');
	    $realname = I('post.realname');
	    $province_id = I('post.province_id', 0);
	    $city_id = I('post.city_id', 0);
	    $area_id = I('post.area_id', 0);
	    $address = I('post.address');
	    $is_default = I('post.is_default',0);
	    
	    $Member_receive = M('Member_receive');
	   
	    !$Member_receive->where(array('id'=>$id, 'uid'=>API_UID))->find() && response(-1, '', '参数ID错误');
	    
	    !preg_match('/^0|1$/', $is_default) && response(-1, '', '是否为默认地址只能为0或1');
	    !preg_match('/1[3458]{1}\d{9}$/', $mobile) && response(-1, '', '请正确输入您的手机号码');
	    !preg_match('/^[\x{4e00}-\x{9fa5}]{1,10}+$/u', $realname) && response(-1, '', '请输入联系人，必须为中文');
	    !get_table_field($province_id, 'province_id', 'province_id', 'Hat_province') && response(-1, '', '选择的省份没有匹配对象');
	    !get_table_field($city_id, 'city_id', 'city_id', 'Hat_city') && response(-1, '', '选择的城市没有匹配对象');
	    !get_table_field($area_id, 'area_id', 'area_id', 'Hat_area') && response(-1, '', '选择的区县没有匹配对象');
	    !preg_match('/^[\x{4e00}-\x{9fa5}][\x{4e00}-\x{9fa5}A-Za-z0-9_-]{1,50}+$/u', $address) && response(-1, '', '详细地址长度必须在5~50个字符');
	    //!preg_match('/^.{5,50}+$/', $address) && response(-1, '', '详细地址长度必须在5~50个字符');
	     
	    $data = array(
	        'id' => $id,
	        'realname' => $realname,
	        'mobile' => $mobile,
	        'province_id' => $province_id,
	        'city_id' => $city_id,
	        'area_id' => $area_id,
	        'address' => $address,
	        'is_default' => $is_default,
	        'update_time' => NOW_TIME
	    );	     
	    if($is_default){
	        $Member_receive->where(array('uid'=>API_UID))->setfield('is_default',0);
	    }    
	    	    
	    $Member_receive->save($data) ? response(1) : response(-9);
	}
	
	/**
	 * 获取用户注册错误信息
	 * 
	 * @param  integer $code 错误编码
	 * @return string        错误信息
	 */
	private function showRegError($code = 0){
	    switch ($code) {
	        case -1:  $error = '用户名长度必须在16个字符以内！'; break;
	        case -2:  $error = '用户名被禁止注册！'; break;
	        case -3:  $error = '用户名被占用！'; break;
	        case -4:  $error = '密码长度必须在6-30个字符之间！'; break;
	        case -5:  $error = '邮箱格式不正确！'; break;
	        case -6:  $error = '邮箱长度必须在1-32个字符之间！'; break;
	        case -7:  $error = '邮箱被禁止注册！'; break;
	        case -8:  $error = '邮箱被占用！'; break;
	        case -9:  $error = '手机格式不正确！'; break;
	        case -10: $error = '手机被禁止注册！'; break;
	        case -11: $error = '手机号被占用！'; break;
	        default:  $error = '未知错误';
	    }
	    return $error;
	}
	
	/**
	 * 获取用户字段值
	 * 
	 * @param string $field 字段属性
	 * @return string 字段值
	 * @author Ringo Chan<334258471@qq.com>
	 */
	private function getMemberInfo($field){
	    $Member = D('Member');
	     
	    $info = $Member->where(array('uid'=>API_UID))->find();
	     
	    $info ? response(1, array('nickname'=>$info[$field])) : response(-9, '', '未知错误');
	}
	/**
	 * 更改头像
	 * @param int cover_id
	 */
	public function updateAvatar(){
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);
	    params_exist(array('cover_id'));
	    
	    $M_mbmber=M('member');
	    $cover_id=I('cover_id');
	    $M_mbmber->where(array('uid'=>API_UID))->setfield('avatar',$cover_id)  ?
	    response(1) : response(-9);
	    
	}
	/**
	 * 添加银行卡
	 * @param string card_no
	 * @param string true_name
	 * @param int isdefault
	 */
	public function addBankCard(){
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);
	    params_exist(array('card_no','true_name'));
	       
	    $M_bank_card=M('bank_card');
	    
	    $data = params_post(array('card_no','true_name','is_default'));
	   
	    $is_default=I('post.is_default',0);
	    $data['is_default']=$is_default;
	    ! preg_match('/^0|1$/', $is_default) && response(- 1,'', '是否为默认值只能是0或1');
	    ! preg_match('/^.{0,50}$/', $data['true_name']) && response(- 1,'','真实姓名在20字以内');
	    ! preg_match('/^.{16,19}$/', $data['card_no']) && response(- 1,'', '银行卡号格式错误');
	    
	    $M_bank_card->where(array('card_no'=>$data['card_no'],
	        'uid'=>API_UID))->find() && response(-1,'','已经添加当前银行卡');
	    $data['uid']=API_UID;
	    $data['create_time']=NOW_TIME;
	    if($data['is_default']){
	      $M_bank_card->where(array('uid'=>API_UID))->setfield('is_default',0);
	    }
	    
	    $discrenbank = new DiscernBank();
	    $data['bank_title']=$discrenbank->discern($data['card_no']);
	    if(!$M_bank_card->where(array('uid'=>API_UID,'is_default'=>1))->find()){	    
	        $data['is_default']=1;
	    }
	    $M_bank_card->add($data) ? response(1) : response(9);	    
	}
	
	/**
	 * 银行卡列表
	 */
	public function bankcardList(){
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);
	    $M_bank_card=M('bank_card');
	    $map=array('uid'=>API_UID);
	    $list=$M_bank_card->where($map)->field('id,card_no,true_name,is_default,bank_title')->select();
	    $total=$M_bank_card->where($map)->count();
	    
	    $result=array();
	    $result['total']=$total;
	    $result['result']=$list;
	    
	    $list ? response(1,$result) : response(-2);
	}
	/**
	 * 删除银行卡
	 * @param int id
	 */
	public function delBankCard(){
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);
	    params_exist(array('id'));
	    
	    $id=I('post.id');
	    !is_numeric($id) && response(-1,'','id错误');
	    $map=array('id'=>$id,'uid'=>API_UID);
	    
	    $M_bank_card=M('bank_card');
	    !$M_bank_card->where($map)->find() && response(-2,'','银行卡不存在');
	    
	    $result=$M_bank_card->where($map)->delete();
	    if($result){
	        $map['is_default']=1;
	        if(!$M_bank_card->where($map)->find()){	               
	               $otm_id=$M_bank_card->where(array('uid'=>API_UID))->getfield('id');
	                $M_bank_card->where(array('id'=>$otm_id))->setfield('is_default',1);
	            }
	        }
	    
	    $result ? response(1) : response(-9);	    
	}
	
	/**
	 * 设置默认银行卡
	 * @param int id
	 */
	public function setdefaultCard(){
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);
	    params_exist(array('id'));
	     
	    $id=I('post.id');
	    !is_numeric($id) && response(-1,'','id错误');
	    $map=array('id'=>$id,'uid'=>API_UID);
	    
	    $M_bank_card=M('bank_card');
	    !$M_bank_card->where($map)->find() && response(-2,'','银行卡不存在');
	     
	    $M_bank_card->where(array('uid'=>API_UID))->setfield('is_default',0);
	    
	    $M_bank_card->where($map)->setfield('is_default',1) !==false  ? response(1) : response(-9);
	}
	
	/**
	 * 统计
	 */
	public function statistics(){
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);
	     
	    $result=array();
	    $map=array();
	    $map['uid']=API_UID;
	     
	    $result['collect_product']=M('collect_product')->where($map)->count();
	    $result['collect_shop']=M('collect_shop')->where($map)->count();
	    $result['collect_browse']=M('collect_browse')->where($map)->count();
	     
	    $result['order_no_pay']=M('order')->where(array('uid'=>API_UID,'status'=>0))->count();
	    $result['order_no_shipments']=M('order')->where(array('uid'=>API_UID,'status'=>1))->count();
	    $result['order_no_receipt ']=M('order')->where(array('uid'=>API_UID,'status'=>array('BETWEEN','2,4')))->count();
	    $result['order_no_comment']=M('order')->where(array('uid'=>API_UID,'status'=>5))->count();
	    $result['order_goods_return']=M('order')->where(array('uid'=>API_UID,'status'=>6))->count();
	     
	    response(1,$result);
	}
	/**
	 * 我的钱包
	 */
	public function Mywallet(){
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);
	    
	    $result=array();
	    $map=array();
	    $map['uid']=API_UID;
	    
	    $wallet=M('member')->where(array('uid'=>API_UID))->field('uid,amount,freeze_amount')->find();
	    
	    response(1,$wallet);
	}
	
	
	/**
	 * 用户头像
	 */
    public function avatarPath(){
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);
        $M_member=M('member');
        $user_info=$M_member->where(array('uid'=>API_UID))->find();
        
        $user_info ? response(1,array('avatar_path'=>get_url($user_info['avatar']))) : resourcebundle_count(-2);
    }
    
    /**
     * 修改头像
     * @param int cover_id
     */
    public function modifyAvatar(){
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);
        params_exist(array('cover_id'));
        
        $cover_id=I('post.cover_id');
        !get_table_field($cover_id,'id','id','picture') && response(-2,'上传的头像不存在');
        $M_member=M('member');
        $M_member->where(array('uid'=>API_UID))->setfield('avatar', $cover_id) !==false ? response(1) : response(-9);
        
    }
    
    /*
     * 获取用户基本信息
     */
    public function BaseInfo()
    {
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);
    
        $info = M('member')->where(array('uid' => API_UID)) ->find();
        if ($info) {
            $info['avatar_path'] = get_url($info['avatar']);
        }
       
        $ext_info=M('ucenter_member')->where(array( 'id' => API_UID )) ->field( array( 'username', 'email')) ->find();
        if ($info  && $ext_info) {
            $info=array_merge($info,$ext_info);
        } 
        
        $info && response(1,$info) && response(-2);
    }
    /**
	 * 完善信息
    */
    public function completeInfo() {
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);
        $nickname = I('post.nickname');
        $is_exist = M('member')->where("nickname='".$nickname."'")->find();
        $uid = API_UID;
        $username = M('member')->where('uid='.$uid)->getField('nickname');

        $data = array(
        	'avatar'=>I('post.cover_id'),//图片的id
			'nickname' => $nickname,//用户名
			'sex' =>I('post.sex'),//性别
			'district' => I('post.district'),//地区
			'sign' => I('post.sign'),//个人签名
        );
		$hx = new HxController();
		$hxresult = $hx->editNickname($username, $nickname);
        $result = M('member')->where('uid='.$uid)->save($data);
        $hxresult && $result && response(1,$result) && response(-2);
	}
	/**
	 * 赠送转让积分
	 */
	public function giveScore(){
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);
		//--uid 赠送给谁那个用户 id score_num 赠送数量
		params_exist(array('uid','score_num'));
		//--赠送数量
		$score_num = (int)I('post.score_num');
		if($score_num<1){
			response(-1, '赠送数量不能小于1');
		}
		//--赠送给谁
		$username = I('post.uid');
		$score = M('member')->where('uid='.API_UID)->getField('score');
		if($score>I('post.score_num')){
			$member = M('ucenter_member')->Where('username='.$username)->join('__MEMBER__ m on __UCENTER_MEMBER__.id=m.uid')->find();
			IF($member['uid']==API_UID){
				response(-1,'您不能自己赠送自己积分');
			}
			if($member){
				
				$shop_u=M('shop')->where(array('uid'=>$member['uid']))->find();
                $shop_u_s=M('shop')->where(array('uid'=>API_UID))->find();
                if(empty($shop_u) && empty($shop_u_s)){
                    if(M('member')->where('uid='.$member['id'])->Save(array(
                        'score' => $member['score']+$score_num
                    ))){
                        M('member')->Where('uid='.API_UID)->Save(array(
                            'score' => $score-$score_num,
                        ));
                        response(1,'积分赠送成功');
                    }

                }else if(!empty($shop_u) && empty($shop_u_s)){
                    M('shop')->where(array('uid'=>$member['uid']))->setInc('recover_score',$score_num);
                    M('member')->Where('uid='.API_UID)->Save(array(
                        'score' => $score-$score_num,
                    ));
                    response(1,'积分赠送成功');
                }else if(!empty($shop_u) && !empty($shop_u_s)){

                    M('shop')->where(array('uid'=>$member['uid']))->setInc('recover_score',$score_num);
                    M('shop')->where(array('uid'=>API_UID))->setInc('give_score',$score_num);
                    M('member')->Where('uid='.API_UID)->Save(array(
                        'score' => $score-$score_num,
                    ));
                    response(1,'积分赠送成功');
                }else if(empty($shop_u) && !empty($shop_u_s)){
                    if(M('member')->where('uid='.$member['id'])->Save(array(
                        'score' => $member['score']+$score_num
                    ))){
                    	M('shop')->where(array('uid'=>API_UID))->setInc('give_score',$score_num);
                        M('member')->Where('uid='.API_UID)->Save(array(
                            'score' => $score-$score_num,
                        ));
                        response(1,'积分赠送成功');
                    }
                }else{
                    response(-1,'未知错误');
                }


			}else{
				response(-1,'此用户不存在');
			}
		}else{
			response(-1,'您的积分不足！');
		}
	}

	/**
	 * 获取用户积分
	 */
    public function getScore(){
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);

	    $Ucenter_member = M('member');
	    $info = $Ucenter_member->find(API_UID);
	    $info ? response(1, array('score'=>$info['score']),'积分获取成功') : response(-9);
    }
    public function sign() {
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);
        $filters['create_time'][] = array('egt', strtotime(date('Y-m-d 00:00:00')));
        $filters['create_time'][] = array('elt', strtotime(date('Y-m-d 23:59:59')));
        $filters['uid'] = array('eq', API_UID);
        $info = M('member_sign')->where($filters)->find();
        $info && response(-1, null, '已签到');
        $id = M('member_sign')->add(array('uid'=>API_UID, 'create_time'=>NOW_TIME));
        $id > 0 || response(-9);
        M('member_gift')->add(array('uid' => API_UID, 'gift' => MemberGiftModel::ZHANGSHENG, 'create_time' => NOW_TIME));
        $userInfo = M('member')->where(array('uid'=>API_UID))->find();
        $total = M('member_sign')->where(array('uid'=>API_UID))->count() | 0;
        $level = calculation_level($total);
        if ($userInfo['level'] < $level) {
            M('member')->save(array('uid'=>API_UID, 'level'=>$level));
            for ($i = $userInfo['level']; $i < $level; $i++) {
                for ($j = 0; $j <= $i; $j++) {
                    M('member_gift')->add(array('uid' => API_UID, 'gift' => MemberGiftModel::XIAOMUZHI, 'create_time' => NOW_TIME));
                }
            }
        }
        response(1);
    }
    // 获取用户掌声，拇指
    public function gift() {
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);
        $result = array();
        $result['zhangsheng']['total'] = M('member_gift')->where(array('uid'=>API_UID, 'gift'=>MemberGiftModel::ZHANGSHENG))->count() | 0;
        $result['zhangsheng']['unused'] = M('member_gift')->where(array('uid'=>API_UID, 'gift'=>MemberGiftModel::ZHANGSHENG, 'is_used'=>0))->count() | 0;
        $result['xiaomuzhi']['total'] = M('member_gift')->where(array('uid'=>API_UID, 'gift'=>MemberGiftModel::XIAOMUZHI))->count() | 0;
        $result['xiaomuzhi']['unused'] = M('member_gift')->where(array('uid'=>API_UID, 'gift'=>MemberGiftModel::XIAOMUZHI, 'is_used'=>0))->count() | 0;
        
        response(1, $result);
    }
    // 送礼物
    public function useGift() {
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);
        $shopId = I('post.shopId', 0);
        $gift = I('post.gift', 0);
        $quantity = I('post.quantity', 1);
        $giftInfo = getGifts($gift);
        (empty($giftInfo) || is_array($giftInfo)) && response(-1, null, '参数有误');
        $shopInfo = M('shop')->where(array('id'=>$shopId, 'apply_uid'=>array('gt',0), 'status'=>1))->find();
        $shopInfo || response(-1, null, '指定店铺不存在');
        intval($quantity) < 1 && response(-1, null, '使用数量至少为1');
        $total = M('member_gift')->where(array('uid'=>API_UID, 'gift'=>$gift, 'is_used'=>0))->count() | 0;
        ($total > 0 && $total >= intval($quantity)) || response(-2, null, '数量不足');
        if ($gift == MemberGiftModel::ZHANGSHENG) {
            $field = 'gift_zhangsheng';
        } elseif ($gift == MemberGiftModel::XIAOMUZHI) {
            $field = 'gift_xiaomuzhi';
        } else {
	        response(-1,'礼物类型有误');
        }
        $memberGifts = M('member_gift')->where(array('uid'=>API_UID, 'gift'=>$gift, 'is_used'=>0))->limit(0,$quantity)->select();
        foreach ($memberGifts as $memberGift) {
            M('member_gift')->where(array('id'=>$memberGift['id']))->save(array('is_used'=>1, 'use_time'=>NOW_TIME, 'sid'=>$shopId));
        }
        M('shop')->where(array('id'=>$shopId))->setInc($field, $quantity);
        response(1);
    }



	//用户充值
	function recharge(){
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);
		params_exist(array('price','channel'));

		$price = floatval(I('post.price'));
		$channel = I('channel');

		$data = array();
		$data['indent'] 	= time()+rand(1,9999);
		$data['u_id']		= API_UID;
		$data['type'] 		= 1;
		$data['price'] 		= $price;
		$data['position'] 	= '充值'.$price.'元';
		$data['time']   	= time();

		/** 执行充值创建订单 modify by zhang 2016 start  **/
		
		/** 执行充值创建订单 modify by zhang 2016 end **/

		$result = M('member_bill')->add($data);
		if ($result) {
			response(1);
		}else{
			response(-9);
		}
	}
	//提现
	function withdraw(){
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);
		//params_exist(array('price','bankname','name','tel','kahao'));

		$price = floatval(I('price'));
		$bankname = I('bankname');
		$name = I('name');
		$tel = I('tel');
		$kahao = I('kahao');

		$user_amount = M('member')->where(array('uid'=>API_UID))->getField('amount');
		if ($user_amount < $price) {
			response(-2,"余额不足");
		}

		// 添加提现记录
		$data = array(
			'price'	=> $price,
			'u_id'	=> API_UID,
			'bankname'	=> $bankname,
			'name'	=> $name,
			'tel'	=> $tel,
			'kahao'	=> $kahao,
			'time'	=> NOW_TIME
		);
		M('member_bill')->startTrans();
		$r1 = M('member_withdraw')->add($data);

		// 添加金额操作记录
		$bill = array(
			'indent' => time() + rand(1,9999),
			'u_id'	=> API_UID,
			'state'	=> 2,
			'price'	=> $price,
			'position'	=> '提现'.$price.'到'.$bankname,
			'payment'	=> '提现'
		);
		$r2 = M('member_bill')->add($bill);
		$r3 = M('member')->where(array('uid'=>API_UID))->setDec('amount',$price);
        /* 添加资金流水记录 modify by liujb 20170208 start */
        addCapitalflow('提现',"-".$price,API_UID);
        /* 添加资金流水记录 modify by liujb 20170208 start */
		if ($r1 && $r2 && $r3) {
			M('member_bill')->commit();
			response(1);
		}else{
			M('member_bill')->rollback();
			response(-9);
		}
	}
	//我的提现记录
	function withdrawlist(){
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);
        $page = I('page',1);
        $page_size = I('page_size',15);
		$list = M('member_withdraw')->where(array('u_id'=>API_UID))->order('time desc')->limit(($page - 1) * $page_size,$page_size)->select();
		response(1,$list);
	}
	//我的余额
	function balance(){
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);
		$amount = M('member')->where(array('uid'=>API_UID))->getField('amount');
		response(1,array('amount'=>$amount));
	}
	//消费记录
	function expenseList(){
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);

        $page = I('page',1);
        $page_size = I('page_size',15);

		$order_list = M('order')->field('price,"购物消费",pay_time as time')
					->where(array('uid'=>API_UID,'pay_time'=>array('gt',0)))
					->order('time desc')
					->buildSql();

		$bill_list = M('member_bill')->field('price,position as info,time')
					->where(array('state'=>1,'u_id'=>API_UID))
					->order('time desc')
					->buildSql();
		$list = M()->query("select * from ".$bill_list ." as aaa"." union ".$order_list." order by time desc limit ".($page - 1) * $page_size.",".$page_size);
		response(1,$list);
	}


	//好友间转账
	function transfer(){
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);

        params_exist(array('fid','price'));
        $fphone = I('fid',0);
        $price = floatval(I('price'));
		$fid = M('ucenter_member')->where('username='.$fphone)->getField('id');
        $user_amount = M('member')->where(array('uid'=>API_UID))->getField('amount');
        if ($user_amount < $price) {
        	response(-2,"余额不足");
        }
        M('member')->startTrans();

        $r1 = M('member')->where(array('uid'=>API_UID))->setDec('amount',$price);
        /* 添加资金流水记录 modify by liujb 20170208 start */
        addCapitalflow('好友转账',"-".$price,API_UID);
        /* 添加资金流水记录 modify by liujb 20170208 end */
        $r2 = M('member')->where(array('uid'=>$fid))->setInc('amount',$price);
        /* 添加资金流水记录 modify by liujb 20170208 start */
        addCapitalflow('好友转账',"+".$price,$fid);
        /* 添加资金流水记录 modify by liujb 20170208 end */
        $names_arr = M('member')->field('id,nickname')->where(array('uid'=>array('in',API_UID.",".$fid)))->select();
		$name = array();
        foreach ($names_arr as $key => $value) {
        	$name[$value['uid']] = $value['nickname'];
        }
        // 用户转账记录
        $data = array(
        	'indent'	=>	time() + rand(1,9999),
        	'u_id'		=>	API_UID,
        	'state'		=>	1,
        	'price'		=>	$price,
        	'position'	=>	'转给'.$name[$fid]." ".$price.'元',
        	'payment'	=>	'ye',
        	'WIDtrade_no'	=>	'zhuanzhang',
        	'time'		=>	NOW_TIME,
        	'commit'	=> $name[$fid]
        );
        $r3 = M('member_bill')->add($data);
        // 用户收入记录
        $data = array(
        	'indent'	=>	time() + rand(1,9999),
        	'u_id'		=>	$fid,
        	'type'		=>	1,
        	'price'		=>	$price,
        	'position'	=>	$name[API_UID].'转入'.$price.'元',
        	'payment'	=>	'ye',
        	'WIDtrade_no'	=>	'zhuanzhang',
        	'time'		=>	NOW_TIME,
        	'commit'	=> $name[$fid]
        );
        $r4 = M('member_bill')->add($data);

		if($r1 && $r2 && $r3 && $r4){
			M('member')->commit();
			response(1);
		}else{
			M('member')->rollback();
			response(-9);
		}
	}
	//转帐记录
	function zhuanzhang(){
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);

        $list = M('member_bill')->field('price,time,comment')
        		->where(array('WIDtrade_no'=>'zhuanzhang','u_id'=>API_UID))
        		->select();
        response(1,$list);
	}

	/*
	 * 获取银行卡数量的
	 * */
	public function getCount() {
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);

        $count = M('bank_card')->where('uid='.API_UID)->count();
        $count = $count?$count:0;
        response(1,$count);
	}
	/**
	 * 我的钱包
	 */
	public function myAssets() {
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);
		$result = array();
		$uid = API_UID;
		//获取我的余额
		$result['amount'] = M('member')->where('uid='.$uid)->getField('amount');

		//商家账户余额
		$where['uid'] = $uid;
		$where['review'] =1;
		$data = M('shop')->where($where)->find();
		if ($data) {
			$bond = M('bond')->find();
			$result['shopAmount'] = $bond['money'];
		} else {
			$result['shopAmount'] = 0;
		}
		//总资产
		$result['count'] = $result['amount'] + $result['shopAmount'];
		//银行卡数量
		$bankCount = M('bank_card')->where('uid='.$uid)->count();
		$result['bankCount'] = $bankCount?$bankCount:0;
		response(1, $result);
	}

    /**
     *充值订单
     * @param  amount
     */
    public function rechargeOrder(){
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);
        params_exist(array('amount'));
        $data = array(
            'uid'              =>  API_UID,
            'order_no'     => build_order_no(),
            'amount'       => I('post.amount'),
            'status'          => 0,
            'create_time' => NOW_TIME,
            'update_time'=>NOW_TIME
        );
        $recharge = M('recharge_order');
        $InsertId   = $recharge->add($data);
        $data = M('recharge_order')->where('id='.$InsertId)->getField('order_no');
        if ($InsertId){
            response(1, $data);
        }else{
            response(-2);
        }
    }
    public function identify() {
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);
        $uid = API_UID;
		$data = array(
			'username' => I('username'),
			'card' => I('card'),
			'covers_id' => I('covers_id')
		);
		$data['uid'] = $uid;
		$data['type'] = 0;
        $res = M('identifycard')->where('uid='.$uid)->find();
		if($res){
            $data['id'] = $res[id];
            $result = M("identifycard")->save($data);
		}else{
			$result = M("identifycard")->add($data);
		}
		$result?response(1):response(-9);
	}
	public function hasIdentify() {
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);
        $uid = API_UID;
        $res = M('identifycard')->where('uid='.$uid)->find();
        $res?response(1,$res):response(-9);
	}

    //提现
    function withdraw1(){
        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);
        $uid = API_UID;
        params_exist(array('price','bankname','name','tel','kahao'));

        $price = floatval(I('price'));
        $bankname = I('bankname');
        $name = I('name');
        $tel = I('tel');
        $kahao = I('kahao');

        $user_amount = M('shop')->where(array('uid'=>$uid))->getField('amount');
        if ($user_amount < $price) {
            response(-2,"余额不足");
        }

        // 添加提现记录
        $data = array(
            'price'	=> $price,
            'u_id'	=> $uid,
            'bankname'	=> $bankname,
            'name'	=> $name,
            'tel'	=> $tel,
            'kahao'	=> $kahao,
            'time'	=> NOW_TIME
        );
        M('member_bill')->startTrans();
        $r1 = M('member_withdraw')->add($data);
        // 添加金额操作记录
        $bill = array(
            'indent' => time() + rand(1,9999),
            'u_id'	=> $uid,
            'state'	=> 2,
            'price'	=> $price,
            'position'	=> '提现'.$price.'到'.$bankname,
            'payment'	=> '提现'
        );
        $r2 = M('member_bill')->add($bill);
        $r3 = M('shop')->where(array('uid'=>$uid))->setDec('amount',$price);
        /* 添加资金流水记录 modify by liujb 20170208 start */
        addCapitalflow('提现',"-".$price,$uid);
        /* 添加资金流水记录 modify by liujb 20170208 end */
        if ($r1 && $r2 && $r3) {
            M('member_bill')->commit();
            response(1);
        }else{
            M('member_bill')->rollback();
            response(-9);
        }
    }
}
?>
